<?php

session_start();

$customer_id = $_SESSION['userid'];

$product_row_id = $_POST['product_row_id'];

if(!isset($_POST['product_row_id'])) {header('Location: index.php');}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Second Hand Horse Saddles | Buy Saddles Online</title>

<link href="css/header.css" rel="stylesheet" type="text/css">
<link href="css/navigation.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="js/product_details_payment_calcs2.js"></script>

<style type="text/css">
body {
	background-image: url(images/wood.jpg);
	background-repeat: repeat-x;
	margin: 0px;
	background-position: left top;
	background-attachment: fixed;
	background-color: #000000;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
}
</style>
<link href="css/product_details.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
</script>
</head>

<body>

<div id="page_container">

<?php include "connect.php" ?>

<?php include "header.php" ?>

<?php include "navigation.php" ?>

<div id="product_container">

<?

//create a list of products that are being watched by the customer
//if the customer is logged in then create array
if($customer_id > 0) 

{

	$alert_list = array();
	$query = "SELECT * FROM customer_alerts WHERE customer_id = $customer_id";
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result))
	
		{
    		array_push($alert_list,$row['product_id']);
    	}

}

//get saddle status

$product_query = "SELECT * FROM saddles WHERE id = $product_row_id";
$product_result = mysql_query($product_query);
while($product_row = mysql_fetch_array($product_result))

{
	
$product_id 			= $product_row['product_id'];
$product_type 			= $product_row['product_type'];
$product_catagory 		= $product_row['product_catagory'];
$product_sub_catagory	= $product_row['product_sub_catagory'];
$product_name 			= $product_row['product_name'];
$product_status 		= $product_row['product_status'];
$product_cost 			= $product_row['product_cost'];
$product_description	= $product_row['product_description'];
$product_make 			= $product_row['product_make'];
$product_colour 		= $product_row['product_colour'];
$product_size			= $product_row['product_size'];
$product_offer 			= $product_row['product_offer'];

}



if($product_status == "On-trial")
{

	//guest
	if($customer_id == 0) //User not logged in
	{

	echo  '<div id="trial_alert">
		   <p><b>On trial</b>Register your email and we will alert you when this saddle becomes available.</p>
		   <form action="add_alertlist.php" method="post" name="trial_alert">
		   <input name="product_id" type="hidden" value="'.$product_id.'" />
		   <input id="alert_email" name="customer_email" type="text" placeholder="Enter your email address" /> 
		   <input id="alert_button" name="alert_button" type="submit" value="Alert" />
		   <a>Terms & conditions</a> 
	       </form>
	       </div>
	       <!--trial_alert-->'
	;}

	//member
	if($customer_id > 0) //User is logged in
	{
		//Has alert set up already
		if((in_array($product_id, $alert_list)) ) //
		{
		
		echo  '<div id="trial_alert">
		  	   <p><b>On trial</b> Email alert active</p>
		  	   <form action="" method="post" name="trial_alert"> 
	      	   </form>
	      	   </div>
	      	   <!--trial_alert-->'
		
		;} else
		
		//Has no alert set up
		{
	
		echo  '<div id="trial_alert">
		  	   <p><b>On trial</b>Set up an alert and we will email you when this saddle becomes available.</p>
		  	   <form action="add_alertlist.php" method="post" name="trial_alert">
		 	   <input name="product_id" type="hidden" value="'.$product_id.'" />
		  	   <input id="alert_email" name="customer_email" type="hidden" placeholder="Enter your email address" /> 
		  	   <input id="alert_button" name="alert_button" type="submit" value="Alert" />
		   	   <a>Terms & conditions</a> 
	      	   </form>
	      	   </div>
	      	   <!--trial_alert-->'
		
		;}

	;}

}

?>  

<img src="images/saddles/<?php  echo $product_row_id ?>_1.jpg" name="large_image" width="500" height="500" id="large_image" />

<h1><?php echo $product_name ?></h1>

<p id="product_cost"><i>Only</i>£<?php echo $product_cost ?></p>

<p id="product_description"><?php echo $product_description ?>

<br /><br />

<b>Availability: </b><?php echo $product_status ?>

<?php 

if ($product_status != "On-trial") { $buy_button_type = "button";} else { $buy_button_type = "hidden";}

?>

<input 
id="add_cart" name="add_cart" type="<?php echo $buy_button_type ?>" 
onclick="MM_changeProp('black_out','','display','block','DIV')" 
value="Buy now" 
/>

 
</p>

<div id="small_images">

<h2>Product images</h2>

  <img src="images/saddles/<?php  echo $product_row_id ?>_2.jpg" id="small_image" onmouseover="MM_swapImage('large_image','','images/saddles/<?php  echo $product_row_id ?>_2.jpg',0)" onmouseout="MM_swapImgRestore()" />
  
  <img src="images/saddles/<?php  echo $product_row_id ?>_3.jpg" id="small_image" onmouseover="MM_swapImage('large_image','','images/saddles/<?php  echo $product_row_id ?>_3.jpg',0)" onmouseout="MM_swapImgRestore()" />
  
  <img src="images/saddles/<?php  echo $product_row_id ?>_4.jpg" id="small_image" onmouseover="MM_swapImage('large_image','','images/saddles/<?php  echo $product_row_id ?>_4.jpg',0)" onmouseout="MM_swapImgRestore()" />
  
</div>




<div id="additional_information">

<h2>Product information - <i>Product ID:<?php echo $product_id ?></i></h2>

<table width="960px" border="0" cellpadding="3">
	<tr>
    <td width="200px"><b>Make</b></td>
    <td><?php echo $product_make ?></td>
  </tr>
  <tr>
    <td width="200px"><b>Colour</b></td>
    <td><?php echo $product_colour ?></td>
  </tr>
  <tr>
    <td width="200px"><b>Size</b></td>
    <td><?php echo $product_size ?></td>
  </tr>
  <tr>
    <td width="200px"><b>Width</b></td>
    <td>Medium</td>
  </tr>
  <tr>
    <td width="200px"><b>Saddle type</b></td>
    <td><?php echo $product_sub_catagory ?></td>
  </tr>
</table>

<?php 
//print customer watch list
//TURNED OFF	print_r($alert_list); 
?>

<h2>Purchase information</h2>

<ul>
<li>FREE TRIAL available on all saddle purchases</li>
<li>Purchase online with a secure PAY PAL payment</li>
<li>Purchase by cash payment on collection</li>
</ul>

</div>
<!--additional_information-->

</div>
<!--product_container-->

<div id="black_out">
<div id="purchase_details">


<form id="form1" name="form1" method="post" action="">

<h2 class="total_cost">Total cost <b>£<span id="total_cost_display"><?php echo $product_cost ?></b></span></h2>

<!--Delivery Cost-->
<input name="delivery_cost" type="hidden" id="delivery_cost_amount" value="0" />

<!--Saddle Cost-->
<input name="saddle_cost" type="hidden" id="saddle_cost_amount" value="<?php echo $product_cost ?>" />

<!--Paypal charge-->
<input name="paypal_cost" type="hidden" id="paypal_cost_amount" value="0" />

<!--Delivery Cost-->
<input name="total_cost" type="hidden" id="total_cost_amount" value="0" />

<div id="options_container">

<h2><b>1.</b>Delivery options</h2>

<p>Choose your delivery method below. Please note if you choose to have your saddle delivered there will be a £13 delivery cost additional to your saddle cost.</p>

      <input name="delivery_options" type="radio" class="hidden" id="delivery_options_0" 
      onclick="MM_changeProp('cash_payment','','display','block','DIV');MM_callJS('collection_selected ()')"
      value="0.00" />
      <label value="delivery" id="delivery" for="delivery_options_0">Collection + £0.00</label>


      <input name="delivery_options" type="radio" class="hidden" id="delivery_options_1" 
      onclick="MM_changeProp('cash_payment','','display','none','DIV');MM_callJS('delivery_selected ()')"
      value="13.00"  />
      <label for="delivery_options_1">Delivery + £13.00</label>
      

<h2><b>2.</b> Payment method</h2>

<p>Choose how you would like to make payment for your saddle. Please note if you have chosen to have your saddle delivered full payment will need to be made via paypal. Please note an additional £xx.xx will be charged on your total payment to cover pay pal fees.</p>


  <div id="cash_payment">

      <input name="payment_options" type="radio" class="hidden" id="payment_options_0" onclick= "MM_callJS('cashpayment_selected ()')" value="Cash payment" />
      <label for="payment_options_0">Cash payment</label>
    </div>

      <input name="payment_options" type="radio" class="hidden" id="payment_options_1" onclick= "MM_callJS('paypal_selected ()')" value="Paypal" />
      <label for="payment_options_1">Paypal</label>

</div>

      <input name="back" type="button" id="back_button" onclick="MM_changeProp('black_out','','display','none','DIV')" value="Cancel" />
      <input name="continue" type="button" id="continue_paypal" onclick= "MM_callJS('continue_payment ()')" value="Continue" />
  
</form>

</div>
<!--Purchase details-->
</div>
<!--Black out-->

</div> 
<!--page_container-->

<?php include "footer.php" ?>

</body>
</html>